from typing import List


class Solution:
    def getMaximumConsecutive(self, coins: List[int]) -> int:
        d = set([0])  # 初始化，空集表示什么都不选

        for coin in coins:
            copyy = set()
            for j in d:
                # 关键修改：只考虑选择当前硬币一次的情况
                copyy.add(j + coin)

            # 在更新 d 之前创建新的 d
            new_d = d.copy()  # 避免修改正在迭代的集合d

            for newItem in copyy:  #
                new_d.add(newItem)
            d = new_d  # 将新的数据写入d
        d = list(d)
        d.sort()
        n = len(d)
        ans = 0
        length = 1
        for i in range(1, n):
            if d[i] == d[i-1] + 1:
                length += 1
            else:
                length = 1
            ans = max(ans, length)
        return ans


if __name__ == '__main__':
    s = Solution()
    r = s.getMaximumConsecutive([1,3,4])
    print(r)